var core = require('core');
var config = core.wechat.config;
var wapi = core.wechat.api;

var types = {
    "create" : "post",
    "get" : "get",
    "update" : "post",
    "delete" : "post",
    "user-get" : "post",
    "members/batchtagging" : "post",
    "members/batchuntagging" : "post",
    "getidlist" : "post"
};

var tags = function(data, callback){
    var method = types[data.url];
    var url = data.url.split('-');
    var type = url.length === 1 ? "" : url[0]+'/';
    url = url.length === 1 ? url[0] : url[1];
    url = method === 'post' ? url + '?access_token='+ config.accessToken : url;
    if(method === "get")
        data.access_token = config.accessToken;

    delete data.url;
    if(method === 'post')
        wapi[method]('cgi-bin/'+ type +'tags/'+ url, data, 'json', callback);
    else
        wapi[method]('cgi-bin/'+ type +'tags/'+ url, data, callback);
};

module.exports = tags;
